require('../css/commonCss/normalize.css')
require('../css/commonCss/basic.css')
require('../css/commonCss/property.css')
require('../css/commonCss/reset.css')

require('weui')
const weUi = require('weui.js')

require('../liabs/iconfont/iconfont.css')
require('../css/logoin.less')

const axios = require('axios')





document.addEventListener('DOMContentLoaded',function(){ //文档加载事件

    
    const phone = document.querySelector('#phone')
    const pwd = document.querySelector('#pwd')
    const regsterBtn = document.querySelector('#regsterbtn')
    const errMsg = document.querySelector('#errmsg')
    
    regsterBtn.addEventListener('click',function(){
        
        let phoneVal = phone.value;
        let pwdVal = pwd.value;
    
        if(!/^1[3-9][0-9]{9}$/.test(phoneVal)){
            errMsg.textContent = '手机号错误'
            return;
        }else if (!/^[0-9]{3,6}$/.test(pwdVal)) {
            errMsg.textContent = '密码错误'
        }else{
    
            errMsg.textContent = '';
    
            axios.post('http://139.9.177.51:8099/users/login',{
                account:phoneVal,
                password:pwdVal,
            }).then(function(res){
                if(res.data.status === 0){
                    localStorage.setItem('userId',res.data.data.user.userId) //将userId存储到本地
                    weUi.toast('登录成功');
                    setTimeout(function(){
                        location.href = './home.html'
                    },2000)
                }else{
                    weUi.alert(res.data.msg)
                }
            })
        }
    })
})

